<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>底盘动态</title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../../css/style.css" />
    <link rel="stylesheet" type="text/css" href="../../css/weui.min.css">
    <script type="text/javascript" src="../../script/jquery-1.10.2.min.js"></script>
    <style>
        .empty{ text-align: center; padding: 120px 0; }
    </style>
</head>
<body>
    <div class="container" id="container">
        <div id="divSearch" class="weui_cells weui_cells_form" style="margin-top:0px">
            <div class="weui_cell">
            <div class="weui_cell_hd"><label class="weui_label">号牌号码</label></div>
            <div class="weui_cell_bd weui_cell_primary">
                <input id="txtHPHM" class="weui_input" placeholder="请输入号牌号码"/>
            </div>
            </div>
        <div class="mainbutton">
            <a class="weui_btn weui_btn_primary" href="javascript:;" id="btnLogin" onclick="SearchVehicle()"  > 搜 索 </a>            
        </div>
        <div id="divListHeader" class="weui_cells_title">动态车辆列表</div>
        </div>
    </div> 
</body>
</html>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript">
     var UIListView;
     var dialogBox;
    apiready = function(){
        UIListView = api.require('UIListView');
        dialogBox = api.require('dialogBox');
        GetVehicleByHPHM("");
    };

    function SearchVehicle()
    {
        var vHphm = $("#txtHPHM").val();
        var curData = GetVehicleByHPHM(vHphm);
        ShowList(curData);
    }

    function GetVehicleByHPHM(paraHphm)
    {
        var vUrlRead = $api.getStorage('ServerUrlRead');
        var vSearchUrl = "";
        if(paraHphm == "")
        {
            vSearchUrl = vUrlRead + '/WcfServices/GetAllDPDTVehicles';
        }
        else
        {
            vSearchUrl = vUrlRead + '/WcfServices/GetDPDTVehicleBysHphm/'+paraHphm;
        }

        api.ajax({
            url:vSearchUrl,
            method: 'post',
            contentType: "application/json",
        }, function(ret, err) {
            if (ret.IsSuccess) {
                var vData = InitVehicleList(ret.Data);
                ShowList(vData);
            }
        });
    }

    function InitVehicleList(data)
    {
        if(data.length != 0)
        {
            var vData = new Array([data.length]);
            for (i = 0; i < data.length; i++) {
                var vSFFJ = "";
                if(data[i].JYCS == "1" )
                {
                    vSFFJ = "初检";
                }
                else
                {
                    vSFFJ = "复检";
                }

                vData[i] = {
                    uid: data[i].ID,
                    title: data[i].HPHM + " " + data[i].HPZL + " " + data[i].JYCS,
                    subTitle: data[i].DLSJ + " " + vSFFJ,
                    remark: data[i].LWLSH
                }
            }
            return vData;
        }
        else
        {
            return null;
        }
    }

    function ShowList(vData)
    {
        var vHeight = $("#divSearch").height();
        var vListHeight =api.frameHeight - vHeight;
        UIListView.open({
                rect: {
                    x: 0,
                    y: vHeight,
                    w: api.winWidth,
                    h: vListHeight
                },
                data: vData,
               rightBtns: [
                {
                    bgColor: '#388e8e',
                    activeBgColor: '',
                    width: 70,
                    title: '查看',
                    titleSize: 12,
                    titleColor: '#fff',
                    icon: '',
                    iconWidth: 20
                },
                {
                    bgColor: '#388e8e',
                    activeBgColor: '',
                    width: 70,
                    title: '删除',
                    titleSize: 12,
                    titleColor: '#fff',
                    icon: '',
                    iconWidth: 20
                }],
                styles: {
                    borderColor: '#696969',
                    item: {
                        bgColor: '#AFEEEE',
                        activeBgColor: '#F5F5F5',
                        height: 55.0,
                        imgWidth: 40,
                        imgHeight: 40,
                        imgCorner: 4,
                        placeholderImg: '',
                        titleSize: 16.0,
                        titleColor: '#000',
                        subTitleSize: 13.0,
                        subTitleColor: '#000',
                        remarkColor: '#FF0000',
                        remarkSize: 13,
                        remarkIconWidth: 30
                    }
                },
                fixedOn: api.frameName
            }, function(ret, err) {
                if (ret.eventType == "clickContent") {
                    openSelectList(vData[ret.index]);
                }
                if(ret.eventType == "clickRightBtn")
                {
                    if(ret.btnIndex == 0)
                    {//查看详情
                        ViewVehicleAll(vData[ret.index].remark);
                    }
                    else if(ret.btnIndex == 1)
                    {//删除外观
                         deleteVehicleDT(ret.index,vData[ret.index].uid); 
                    }                        
                }

                UIListView.setRefreshHeader({
                    bgColor: '#F5F5F5',
                    textColor: '#8E8E8E',
                    textDown: '下拉可以刷新...',
                    textUp: '松开开始刷新...',
                    showTime: true
                }, function(ret, err) {
                    if (ret) {
                        GetVehicleByHPHM("");
                    } else {
                    }
                });

            });
    }

    function InitVehicleInfoList(data)
    {
        if(data.length != 0)
        {
            var vData = new Array([16]);
            vData[0] = { text: "号牌号码：" + data.hphm};
            vData[1] = { text: "号牌种类：" + data.hpzl};
            vData[2] = { text: "VIN：" + data.clsbdh};
            vData[3] = { text: "发动机号：" + data.fdjh};
            vData[4] = { text: "检验项目：" + data.jyxm};
            vData[5] = { text: "所有人：" + data.syr};
            vData[6] = { text: "登录员：" + data.dly};
            vData[7] = { text: "车辆品牌：" + data.clpp1};
            vData[8] = { text: "初始登记日期：" + data.ccdjrq};
            vData[9] = { text: "轴距：" + data.zj};
            vData[10] = { text: "前轮距：" + data.qlj};
            vData[11] = { text: "后轮距：" + data.hlj};
            vData[12] = { text: "总质量：" + data.zzl};
            vData[13] = { text: "整备质量：" + data.zbzl};
            vData[14] = { text: "出厂日期：" + data.ccrq};
            vData[15] = { text: "登录时间：" + data.dlsj};

            return vData;
        }
        else
        {
            return null;
        }

    }

    //查看车辆详情
    function ViewVehicleAll(strJYLSH)
    {
        var vUrlRead = $api.getStorage('ServerUrlRead');
        api.ajax({
            url:vUrlRead + '/WcfServices/GetVehicleInfo/'+strJYLSH,
            method: 'post',
            contentType: "application/json",
        }, function(ret, err) {
            if (ret.IsSuccess) {
                var vData = InitVehicleInfoList(ret.Data);
                ShowVehicleInfoList(vData);
            }
        });
    }

    function ShowVehicleInfoList(data)
    {
        dialogBox.scene({
            rect: {
                w: 320,
                h: 400
            },
            texts: {
                title: '车辆详情',
                content: '',
                okBtnTitle: '关闭'
            },
            styles: {
                bg: '#fff',
                title: {
                    bg: '#aaa',
                    h: 44,
                    size: 14,
                    color: '#000'
                },
                sceneImg: {
                    h: 150,
                    path: 'widget://image/sceneImg.png'
                },
                content: {
                    color: '#111',
                    size: 12
                },
                cell: {
                    bg: '#fff',
                    h: 48,
                    text: {
                        color: '#636363',
                        size: 13
                    },
                    icon: {
                        marginL: 15,
                        marginT: 9,
                        w: 30,
                        h: 30,
                        corner: 2
                    }
                },
                ok: {
                    bg: '#89a',
                    titleColor: '#f00',
                     h: 48,
                     size: 16
                }
            },
            optionDatas: data
        }, function(ret, err) {
            if (ret) 
            {
                if(ret.eventType == "ok")
                {
                    dialogBox.close();
                }
            } else {
                alert(JSON.stringify(err));
            }
        });
    }

    function openSelectList(paraData) {
            api.openWin({
                name: 'win_dtjyxm',
                url: 'win_dtjyxm.html ',
                pageParam: {
                    ID: paraData.uid,
                    PlateNum: paraData.title,
                    VIN: paraData.subTitle,
                    LWLSH: paraData.remark
                },
                reload: true,
            });
        }

    function deleteVehicleDT(iIndex,VehicleID)
    {
        api.confirm({
        title: '提示',
        msg: '您确定要删除吗？',
        buttons: ['确定', '取消']
        }, function(ret, err) {
            if( ret.buttonIndex == 1)
            {
                deleteVehicleDTItem(iIndex,VehicleID);
            }

        });
    }

    function deleteVehicleDTItem(iIndex,VehicleID)
    {
        var vUrlWrite = $api.getStorage('ServerUrlWrite');
        api.ajax({
            url:vUrlWrite + '/WcfServices/DeleteDT/' + VehicleID,
            method: 'post',
            contentType: "application/json",
        }, function(ret, err) {
            if (ret.IsSuccess) {
                UIListView.deleteItem({
                    index: iIndex
                }, function(ret, err) {
                    if (ret) {
                    } else {
                        alert(JSON.stringify(err));
                    }
                });
            }
        });
    }

</script>